package com.bvbot.core.bot;

import static com.bvbot.core.Logger.log;

import java.io.FileInputStream;
import java.io.IOException;

import com.bvbot.json.JsonTool;


public class PricesLoader {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		PricesLoader pl = new PricesLoader();
		PricesHistory ph = pl.load("PricesRecord-2011.10.10.dump");
		log("Gold price is " + ph.getCurrentPrice().getGoldWorldValue());
		log("Silver sell price is "
				+ ph.getCurrentPrice().getBvSilverSellValue());
	}

	private PricesHistory load(String fileName) {
		byte[] bytes = null;
		try {
			FileInputStream fis = new FileInputStream(fileName);
			int available = fis.available();
			bytes = new byte[available];
			fis.read(bytes);
		} catch (IOException e) {
			log("Exception : " + e.getMessage(), e);
		}
		PricesHistory result = JsonTool.get().fromJson(PricesHistory.class,
				bytes, true);
		return result;
	}

}
